<?php
/**
 * 测试常量定义
 * @author 王勇程 <laughskydragon@qq.com>
 */

// 引入框架
require_once __DIR__ . '/../vendor/autoload.php';

// 启动应用
$app = new \think\App();
$app->initialize();

echo "<h1>常量检查</h1>";

$constants = [
    'LAYER_MODEL_NAME',
    'LAYER_LOGIC_NAME', 
    'LAYER_VALIDATE_NAME',
    'LAYER_SERVICE_NAME',
    'DATA_STATUS_NAME',
    'DATA_NORMAL',
    'DATA_DISABLE',
    'DATA_DELETE',
    'RESULT_SUCCESS',
    'RESULT_ERROR'
];

foreach ($constants as $const) {
    if (defined($const)) {
        echo "<p style='color: green;'>{$const}: " . constant($const) . "</p>";
    } else {
        echo "<p style='color: red;'>{$const}: 未定义</p>";
    }
}

echo "<h2>分类选择器测试</h2>";

try {
    $categoryLogic = new \app\common\logic\Category();
    $result = $categoryLogic->getCategorySelector();
    
    echo "<p>Code: " . $result['code'] . "</p>";
    echo "<p>Msg: " . $result['msg'] . "</p>";
    echo "<p>Data count: " . count($result['data']) . "</p>";
    
    if (!empty($result['data'])) {
        echo "<ul>";
        foreach ($result['data'] as $item) {
            echo "<li>ID: {$item['id']}, name_with_level: '{$item['name_with_level']}'</li>";
        }
        echo "</ul>";
    }
    
} catch (\Exception $e) {
    echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
    echo "<p>文件: " . $e->getFile() . "</p>";
    echo "<p>行号: " . $e->getLine() . "</p>";
}